package com.itguigu.process.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itguigu.model.process.ProcessTemplate;
import com.itguigu.model.process.ProcessType;
import com.itguigu.process.mapper.ProcessTypeMapper;
import com.itguigu.process.service.ProcessTemplateService;
import com.itguigu.process.service.ProcessTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class ProcessTypeServiceImpl extends ServiceImpl<ProcessTypeMapper , ProcessType> implements ProcessTypeService {

    @Resource
    private ProcessTemplateService processTemplateService;

    @Override
    public List<ProcessType> findProcessType() {
        // 获取所有审批分类
        List<ProcessType> processTypeList = baseMapper.selectList(null);
        // 遍历每一个审批分类
        for (ProcessType processType : processTypeList) {
            // 得到该分类的id
            Long typeId = processType.getId();
            // 根据id去审批模板类中去获取对应的模板信息
            List<ProcessTemplate> wrapper = processTemplateService.list(new LambdaQueryWrapper<ProcessTemplate>().eq(ProcessTemplate::getProcessTypeId, typeId));
            // 将查询到的 模板集合存入 每个审批分类对象里面
            processType.setProcessTemplateList(wrapper);
        }
        return processTypeList;
    }
}
